package jee.boot.module.delegated;

import jee.boot.common.basic.DataEntity;
import jee.boot.module.crud.entity.DemoCrud;
import jee.boot.module.crud.service.DemoCrudService;
import jee.boot.entity.task.IexpTaskConfig;
import jee.boot.entity.task.IexpTask;
import jee.boot.entity.task.ImportExecuteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
@Service
public class DemoImport implements ImportExecuteService {
    @Autowired
    private DemoCrudService demoCrudService;


    @Override
    public void storeData(IexpTask task, Object data) {
        List<? extends DataEntity> dataList=(List<? extends DataEntity>)data;
        if(dataList!=null && !dataList.isEmpty()){
            List<DemoCrud> list= Arrays.asList(dataList.toArray(new DemoCrud[0]));
            demoCrudService.batchSave(list);
        }
    }

    @Override
    public IexpTaskConfig taskConfig(IexpTask task) {
        IexpTaskConfig config = new IexpTaskConfig();
        config.initImportByEntityConfig(DemoCrud.class);
        return config;
    }

}
